#include<iostream>
#include<vector>

int fight(int num) {
    int sign = 0;
    while (num) {
        int x = num % 10;
        sign += x * x;
        num /= 10;
    }
    return sign;
}
bool isHappy(int n) {
    int slow = fight(n), fast = fight(fight(n));
    while (slow != fast) {
        slow = fight(slow);
        fast = fight(fight(fast));
    }
    return slow == 1;
}
int main()
{
    cout<<isHappy(19) << endl;
    return 0;
}